from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from ModuleApp.models import GoodsCategory


def listorders(request):
    """
    未添加过滤
    """
    # 返回一个 QuerySet 对象 ，包含所有的表记录
    # 每条表记录都是是一个dict对象，
    # key 是字段名，value 是 字段值
    qs = GoodsCategory.objects.values()

    # 定义返回字符串
    retStr = ''
    for customerDict in qs:
        for name, value in customerDict.items():
            retStr += f'{name} : {value} | '

        # <br> 表示换行
        retStr += '<br>'

    return HttpResponse(retStr)


# {{ content |truncatechars:2}} 表示字符串最多显示两位超过 ,就显示为...   其中... 也占一位
# content='abc'
# 显示:a...

# {{ views_str|safe }} 表示不需要转义字符串


# {{ views_dict }}
# {{ views_dict.name }}
#
# {{ name|lower }}
# {{ my_list|first|upper }}
#
# {{ bio|truncatewords:"30" }}
#
# {{ pub_date|date:"F j, Y" }}
#
# {{ name|default:"菜鸟教程666" }}
#
#
# {{ name|length}}
# {{ num|filesizeformat}}
#
# {{ time|date:"Y-m-d" }}
#
# {{ content|truncatechars:2}}
#
# {{ views_str|safe }}


def runoob(request):
    views_dict = {}
    views_dict['name'] = 'hELLo world'
    views_dict['bio'] = 'abc30'
    views_dict['num'] = 88
    views_dict['views_str'] = "<a href='https://www.runoob.com/'>点击跳转</a>"
    views_dict['views_list'] = ["aaa", "bbb", "ccc", "ddd", ]
    views_dict['section'] = 'sitenews'
    return render(request, "runoob.html", views_dict)


def runoob1(request):
    dirctContent = {}
    dirctContent['name'] = 'Hello World!'
    return render(request, 'runoob.html', dirctContent)
